# -*- coding: utf-8 -*-
from fastapi import APIRouter, Header, Path
from entity import ConnectionInfo, ColumnInfo

import service


data_router = APIRouter()


@data_router.post('/connect')
async def connect(ci: ConnectionInfo):
    token = service.connect(ci)
    return token


@data_router.get("/schema/list")
async def list_schema(token: str = Header(...)):
    return service.get_schema_list(token=token)


@data_router.get("/table/list/{schema}")
async def list_table(token: str = Header(...), schema: str = Path(...)):
    return service.get_table_list(token=token, schema=schema)


@data_router.get("/column/list/{schema}/{table}")
async def list_column(token: str = Header(...), schema: str = Path(...), table: str = Path(...)):
    return service.get_column_list(token=token, schema=schema, table=table)


@data_router.post("/generate/{count}")
async def generate(token: str = Header(...), count: int = Path(...), column_list: list[ColumnInfo] = None):
    return service.generate_data(token, count, column_list)
